home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / util / moni / Scout-src.lha / netinclude / rpc / clnt.h < prev    next >
C/C++ Source or Header  |  2002-09-16  |  8KB  |  296 lines

  1. #ifndef RPC_CLNT_H
  2. #define RPC_CLNT_H
  3. /*
  4.  * $Id: clnt.h,v 1.1.1.1 2001/11/26 22:21:19 tboeckel Exp $
  5.  *
  6.  * Client side remote procedure call interface.
  7.  *
  8.  * Copyright © 1994 AmiTCP/IP Group,
  9.  *                  Network Solutions Development Inc.
  10.  *                  All rights reserved.
  11.  *
  12.  */
  13. /* @(#)clnt.h    2.1 88/07/29 4.0 RPCSRC; from 1.31 88/02/08 SMI*/
  14.  
  15. /*
  16.  * Copyright (C) 1984, Sun Microsystems, Inc.
  17.  */
  18.  
  19. /*
  20.  * Rpc calls return an enum clnt_stat.  This should be looked at more,
  21.  * since each implementation is required to live with this (implementation
  22.  * independent) list of errors.
  23.  */
  24. enum clnt_stat {
  25.     RPC_SUCCESS=0,            /* call succeeded */
  26.     /*
  27.      * local errors
  28.      */
  29.     RPC_CANTENCODEARGS=1,        /* can't encode arguments */
  30.     RPC_CANTDECODERES=2,        /* can't decode results */
  31.     RPC_CANTSEND=3,            /* failure in sending call */
  32.     RPC_CANTRECV=4,            /* failure in receiving result */
  33.     RPC_TIMEDOUT=5,            /* call timed out */
  34.     /*
  35.      * remote errors
  36.      */
  37.     RPC_VERSMISMATCH=6,        /* rpc versions not compatible */
  38.     RPC_AUTHERROR=7,        /* authentication error */
  39.     RPC_PROGUNAVAIL=8,        /* program not available */
  40.     RPC_PROGVERSMISMATCH=9,        /* program version mismatched */
  41.     RPC_PROCUNAVAIL=10,        /* procedure unavailable */
  42.     RPC_CANTDECODEARGS=11,        /* decode arguments error */
  43.     RPC_SYSTEMERROR=12,        /* generic "other problem" */
  44.  
  45.     /*
  46.      * callrpc & clnt_create errors
  47.      */
  48.     RPC_UNKNOWNHOST=13,        /* unknown host name */
  49.     RPC_UNKNOWNPROTO=17,        /* unkown protocol */
  50.  
  51.     /*
  52.      * _ create errors
  53.      */
  54.     RPC_PMAPFAILURE=14,        /* the pmapper failed in its call */
  55.     RPC_PROGNOTREGISTERED=15,    /* remote program is not registered */
  56.     /*
  57.      * unspecified error
  58.      */
  59.     RPC_FAILED=16
  60. };
  61.  
  62.  
  63. /*
  64.  * Error info.
  65.  */
  66. struct rpc_err {
  67.     enum clnt_stat re_status;
  68.     union {
  69.         int RE_errno;        /* realated system error */
  70.         enum auth_stat RE_why;    /* why the auth error occurred */
  71.         struct {
  72.             u_long low;    /* lowest verion supported */
  73.             u_long high;    /* highest verion supported */
  74.         } RE_vers;
  75.         struct {        /* maybe meaningful if RPC_FAILED */
  76.             long s1;
  77.             long s2;
  78.         } RE_lb;        /* life boot & debugging only */
  79.     } ru;
  80. #define    re_errno    ru.RE_errno
  81. #define    re_why        ru.RE_why
  82. #define    re_vers        ru.RE_vers
  83. #define    re_lb        ru.RE_lb
  84. };
  85.  
  86.  
  87. /*
  88.  * Client rpc handle.
  89.  * Created by individual implementations, see e.g. rpc_udp.c.
  90.  * Client is responsible for initializing auth, see e.g. auth_none.c.
  91.  */
  92. typedef struct CLIENT {
  93.     AUTH    *cl_auth;            /* authenticator */
  94.     struct clnt_ops {
  95.         enum clnt_stat    (*cl_call)(struct CLIENT *rh, u_long proc, 
  96.                        xdrproc_t xargs, void * argsp, 
  97.                        xdrproc_t xres, void * resp, 
  98.                        struct timeval timeout);    /* call remote procedure */
  99.         void        (*cl_abort)(struct CLIENT *rh);    /* abort a call */
  100.         void        (*cl_geterr)(struct CLIENT *rh, 
  101.                          struct rpc_err *errp); /* get specific error code */
  102.         bool_t        (*cl_freeres)(struct CLIENT *rh, 
  103.                           xdrproc_t xres, void * resp); /* frees results */
  104.         void        (*cl_destroy)(struct CLIENT *rh); /* destroy this structure */
  105.         bool_t          (*cl_control)(struct CLIENT *rh, u_int request,
  106.                           void * info); /* the ioctl() of rpc */
  107.     } *cl_ops;
  108.     caddr_t            cl_private;    /* private stuff */
  109. } CLIENT;
  110.  
  111.  
  112. /*
  113.  * client side rpc interface ops
  114.  *
  115.  * Parameter types are:
  116.  *
  117.  */
  118.  
  119. /*
  120.  * enum clnt_stat
  121.  * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
  122.  *     CLIENT *rh;
  123.  *    u_long proc;
  124.  *    xdrproc_t xargs;
  125.  *    void * argsp;
  126.  *    xdrproc_t xres;
  127.  *    void * resp;
  128.  *    struct timeval timeout;
  129.  */
  130. #define    CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs)    \
  131.     ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
  132. #define    clnt_call(rh, proc, xargs, argsp, xres, resp, secs)    \
  133.     ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
  134.  
  135. /*
  136.  * void
  137.  * CLNT_ABORT(rh);
  138.  *     CLIENT *rh;
  139.  */
  140. #define    CLNT_ABORT(rh)    ((*(rh)->cl_ops->cl_abort)(rh))
  141. #define    clnt_abort(rh)    ((*(rh)->cl_ops->cl_abort)(rh))
  142.  
  143. /*
  144.  * void
  145.  * CLNT_GETERR(rh, errp);
  146.  *     CLIENT *rh;
  147.  *      struct rpc_err *errp;
  148.  */
  149. #define    CLNT_GETERR(rh,errp)    ((*(rh)->cl_ops->cl_geterr)(rh, errp))
  150. #define    clnt_geterr(rh,errp)    ((*(rh)->cl_ops->cl_geterr)(rh, errp))
  151.  
  152.  
  153. /*
  154.  * bool_t
  155.  * CLNT_FREERES(rh, xres, resp);
  156.  *     CLIENT *rh;
  157.  *    xdrproc_t xres;
  158.  *    void * resp;
  159.  */
  160. #define    CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
  161. #define    clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
  162.  
  163. /*
  164.  * bool_t
  165.  * CLNT_CONTROL(cl, request, info)
  166.  *      CLIENT *cl;
  167.  *      u_int request;
  168.  *      void *info;
  169.  */
  170. #define    CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
  171. #define    clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
  172.  
  173. /*
  174.  * control operations that apply to both udp and tcp transports
  175.  */
  176. #define CLSET_TIMEOUT       1   /* set timeout (timeval) */
  177. #define CLGET_TIMEOUT       2   /* get timeout (timeval) */
  178. #define CLGET_SERVER_ADDR   3   /* get server's address (sockaddr) */
  179. /*
  180.  * udp only control operations
  181.  */
  182. #define CLSET_RETRY_TIMEOUT 4   /* set retry timeout (timeval) */
  183. #define CLGET_RETRY_TIMEOUT 5   /* get retry timeout (timeval) */
  184.  
  185. /*
  186.  * void
  187.  * CLNT_DESTROY(rh);
  188.  *     CLIENT *rh;
  189.  */
  190. #define    CLNT_DESTROY(rh)    ((*(rh)->cl_ops->cl_destroy)(rh))
  191. #define    clnt_destroy(rh)    ((*(rh)->cl_ops->cl_destroy)(rh))
  192.  
  193.  
  194. /*
  195.  * RPCTEST is a test program which is accessable on every rpc
  196.  * transport/port.  It is used for testing, performance evaluation,
  197.  * and network administration.
  198.  */
  199.  
  200. #define RPCTEST_PROGRAM        (1UL)
  201. #define RPCTEST_VERSION        (1UL)
  202. #define RPCTEST_NULL_PROC    (2UL)
  203. #define RPCTEST_NULL_BATCH_PROC    (3UL)
  204.  
  205. /*
  206.  * By convention, procedure 0 takes null arguments and returns them
  207.  */
  208.  
  209. #define NULLPROC (0UL)
  210.  
  211. /*
  212.  * Below are the client handle creation routines for the various
  213.  * implementations of client side rpc.  They can return NULL if a 
  214.  * creation failure occurs.
  215.  */
  216.  
  217. /*
  218.  * Memory based rpc (for speed check and testing)
  219.  */
  220. extern CLIENT *clntraw_create(u_long prog, u_long vers);
  221.  
  222.  
  223. /*
  224.  * Generic client creation routine. Supported protocols are "udp" and "tcp"
  225.  */
  226. extern CLIENT *
  227. clnt_create(char *host, u_long prog, u_long vers, char *prot);
  228.  
  229.  
  230. /*
  231.  * TCP based rpc
  232.  */
  233. extern CLIENT *clnttcp_create(struct sockaddr_in *raddr, u_long prog, 
  234.                   u_long version, int *sockp,
  235.                   u_int sendsz, u_int recvsz);
  236.  
  237. /*
  238.  * UDP based rpc.
  239.  */
  240. extern CLIENT *clntudp_create(struct sockaddr_in *raddr, u_long program,
  241.                   u_long version, struct timeval wait, int *sockp);
  242. /*
  243.  * Same as above, but you specify max packet sizes.
  244.  */
  245. extern CLIENT *clntudp_bufcreate(struct sockaddr_in *raddr, u_long program,
  246.                  u_long version, struct timeval wait, 
  247.                  int *sockp, u_int sendsz, u_int recvsz);
  248.  
  249. /*
  250.  * Print why creation failed
  251.  */
  252. extern void clnt_pcreateerror(char *msg);    /* stderr */
  253. extern char *clnt_spcreateerror(char *msg);    /* string */
  254.  
  255. /*
  256.  * Like clnt_perror(), but is more verbose in its output
  257.  */ 
  258. extern void clnt_perrno(enum clnt_stat num);    /* stderr */
  259.  
  260. /*
  261.  * Print an English error message, given the client error code
  262.  */
  263. extern void clnt_perror(CLIENT *clnt, char *msg);     /* stderr */
  264. extern char *clnt_sperror(CLIENT *clnt, char *msg);    /* string */
  265.  
  266. /* 
  267.  * If a creation fails, the following allows the user to figure out why.
  268.  */
  269. struct rpc_createerr {
  270.     enum clnt_stat cf_stat;
  271.     struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
  272. };
  273.  
  274. extern struct rpc_createerr rpc_createerr;
  275.  
  276.  
  277.  
  278. /*
  279.  * Copy error message to buffer.
  280.  */
  281. extern char *clnt_sperrno(enum clnt_stat num);    /* string */
  282.  
  283.  
  284.  
  285. #define UDPMSGSIZE    8800    /* rpc imposed limit on udp msg size */
  286. #define RPCSMALLMSGSIZE    400    /* a more reasonable packet size */
  287.  
  288. /*
  289.  * simple rpc
  290.  */
  291. int callrpc(const char * host,
  292.         u_long prognum, u_long versnum, u_long procnum,
  293.         xdrproc_t inproc, void * in, xdrproc_t outproc, void * out);
  294.  
  295. #endif /* !RPC_CLNT_H */
  296.